package com.rivulet.doj_backend.service.impl;

import com.rivulet.doj_backend.mapper.MessageMapper;
import com.rivulet.doj_backend.mapper.QuestionMapper;
import com.rivulet.doj_backend.pojo.Message;
import com.rivulet.doj_backend.service.MessageService;
import com.rivulet.doj_backend.tools.ResultFul;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService{
    @Autowired
    MessageMapper MessageMapper;

    @Override
    public ResultFul addMessage(Integer message_id,Integer message_range,String message_content,Integer publisher_id,Integer relation_class_id){
        ResultFul result;
        try {
            if (publisher_id != null){
                
                MessageMapper.addMessage(message_id,message_range,message_content,publisher_id,relation_class_id);
                result = new ResultFul<Object>(100, null);
            }else {
                result = new ResultFul<Object>(408, null);
            }
        } catch (Exception e){
            System.out.println("addMessage_error:"+e);
            result = new ResultFul<List>(404, null);
        }
        return result;
    }


    @Override
    public ResultFul setUserJoinClass(Integer user_id,Integer class_id) {
        ResultFul result;
        try{
            if(user_id != null && class_id != null) {
                MessageMapper.setUserJoinClass(user_id, class_id);
                result = new ResultFul<Object>(100, null);
            }else {
                result = new ResultFul<Object>(408, null);
            }
        }catch (Exception e) {
            System.out.println("setUserJoinClass_error:" + e);
            result = new ResultFul<Object>(404, null);
        }

        return result;
    }


    @Override
    public ResultFul competitionMessage(Integer user_id,Integer competition_id) {
        ResultFul result;
        try{
            if(user_id != null && competition_id!= null) {
                MessageMapper.competitionMessage(user_id, competition_id);
                result = new ResultFul<Object>(100, null);
            }else {
                result = new ResultFul<Object>(405, null);
            }
        }catch (Exception e) {
            System.out.println("competitionMessage_error:" + e);
            result = new ResultFul<Object>(404, null);
        }

        return result;
    }

    @Override
    public ResultFul addAllMessage(Integer message_id, Integer message_range, String message_content, Integer publisher_id) {
        ResultFul result;
        try {
            if(message_id != null) {
                this.MessageMapper.addAllMessage(message_id, message_range, message_content, publisher_id);
                result = new ResultFul(Integer.valueOf(100), (Object)null);
            } else {
                result = new ResultFul(Integer.valueOf(408), (Object)null);
            }
        } catch (Exception var8) {
            System.out.println("addMessage_error:" + var8);
            result = new ResultFul(Integer.valueOf(404), (Object)null);
        }

        return result;
    }
}
